package com.atm.atmsys.controller.atm;

import com.atm.atmsys.Service.AtmService;
import com.atm.atmsys.dto.ATMPageQueryDTO;
import com.atm.atmsys.dto.AtmDTO;
import com.atm.atmsys.entity.AdminInfo;
import com.atm.atmsys.entity.AtmInfo;
import com.atm.atmsys.entity.PageResult;
import com.atm.atmsys.utils.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/atm")
@Slf4j
public class AtmController {




    @Autowired
    private AtmService atmService;
    //新增ATM
    @PostMapping("/addAtm")
    @ApiOperation("新增ATM机器")
    public Result addAdmin(@RequestBody AtmInfo atmInfo) {
        log.info("新增ATm:{}",atmInfo);
        atmService.addAtm(atmInfo);
        return Result.success();

    }

    //根据Id删除ATM
    @PostMapping("/deleteAtm/{id}")
    @ApiOperation("删除ATM机器")
    public Result deleteAtm(@PathVariable Integer id){
        atmService.deleteAtm(id);
        return Result.success();
    }

    //查询ATM
    @GetMapping("/getAtm")
    @ApiOperation("查询所有ATM机器")
    public Result<PageResult> getAtm(ATMPageQueryDTO atmPageQueryDTO){
        PageResult pageResult= new PageResult();
        pageResult=atmService.getAllAtm(atmPageQueryDTO);
        return Result.success(pageResult);
    }

    //根据ID查询ATM
    @GetMapping("/getAtmById/{id}")
    @ApiOperation("根据id查询ATM机器")
    public Result<AtmInfo> getAtmById(@PathVariable Integer id){
        AtmInfo atmInfo = atmService.getAtmById(id);
        return Result.success(atmInfo);
    }

    //修改ATM
    @PutMapping("/updateAtm")
    @ApiOperation("更新ATM机器的状态")
    public Result updateAtm(@RequestBody AtmDTO atmDTO){
        log.info("修改ATM:{}",atmDTO);
        atmService.updateAtm(atmDTO);
        return Result.success();
    }


    //显示所有ATM不分页
    @GetMapping("/getAtmList")
    @ApiOperation("显示所有ATM机器不分页")
    public Result<List> getAllAtm(){
        List<AtmInfo> atmInfos = atmService.getAtm();
        return Result.success(atmInfos);
    }



}
